package Servlet.control;

import java.io.IOException;
import java.io.PrintWriter;

import javax.jms.Session;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.TForum;
import persistent.dao.ForumDAO;
import persistent.factory.DAOFactory;
import utli.SendRequest;

public class EditfroumServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public EditfroumServlet() {
		super();
	}

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		String titleid =request.getParameter("titleid");
		
		if(titleid==null || titleid.trim().equals("")){
			TForum forum = new TForum();
			request.setAttribute("forum", forum);
		}
		else {
			int id = Integer.parseInt(titleid);
			System.out.println(id);
			ForumDAO fado = DAOFactory.getForumDAO();
			TForum forum = fado.getTForumById(id);
			request.setAttribute("forum", forum);
		}
		try {
			SendRequest.SendDispatcher("editforum.jsp", request, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	doGet(request, response);
	}

}
